package awk.script.javassist.method04.hotswap;

import cn.hutool.core.util.RandomUtil;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;

/**
 * 例子 模拟双色球暗香茶座
 * @author yujianlong
 * @create 2021-03-29 13:54
 **/
public class MyExample  implements Runnable{

	//开关
	public static volatile boolean isOver=false;

	public synchronized String myTest(String name){
		return name+"中奖号码"+ RandomUtil.randomNumbers(10);

	}

//	public String myTest2(String name){
//		isOver=true;
//		return "老板中奖号码888888888";
//	}



	@Override
	public void run() {


		while (!isOver) {
			MyExample myExample = new MyExample();
			String txt = myExample.myTest(RandomUtil.randomString(7));
			if (!isOver) {
				System.out.println(txt+"  isOver="+isOver);
			}

			try {
				TimeUnit.SECONDS.sleep(1);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
		//老板兜底
		String txt = new MyExample().myTest(RandomUtil.randomString(7));
		System.out.println(txt+"  isOver="+isOver);

		System.out.println("结束摇奖");
	}


	public static void main(String[] args) throws InterruptedException {
		CompletableFuture.runAsync(
				new MyExample()
		);

		TimeUnit.SECONDS.sleep(3);

//		MyExample.isOver=true;

		TimeUnit.SECONDS.sleep(3000);

	}
}
